package com.test.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.test.enity.Employee;
import com.test.service.EmployeeService;


@WebServlet("/AddEmployeeServlet")
public class AddEmployeeServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html; charset=UTF-8");
		response.setCharacterEncoding("utf-8");
		//int id=Integer.parseInt(request.getParameter("id"));
		String name=request.getParameter("name");
		String sex=request.getParameter("sex");
		int age=Integer.parseInt(request.getParameter("age"));
		String dpartment=request.getParameter("dapartment");
		String type=request.getParameter("type");
		int year=Integer.parseInt(request.getParameter("year"));
		
		Employee employee=new Employee(name,sex,age,dpartment,type,year);
		EmployeeService employeeService=new EmployeeService();
		boolean result=employeeService.addEmployee(employee);
		PrintWriter out = response.getWriter();
		if (result) {
			response.sendRedirect("QueryAllEmployeeServlet");
		} else {
			out.println("增加失败");
		}
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
